﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using TS_XY_Train_Repaire.Locomotive.TrainRepair;

namespace TS_XY_Train_Repaire.UserCon.ucPub.Map
{
    public partial class uc_Pub_Map_Select_ListView_ByOne : DevExpress.XtraEditors.XtraForm
    {
        public string _LoadType = "0";
        public string _LoadFormType = "0";
        public uc_Pub_Map_Select_ListView_ByOne()
        {
            InitializeComponent();
        }

        private void uc_Pub_Map_Select_ListView_ByOne_Load(object sender, EventArgs e)
        {
            ArrayList pList = new ArrayList();
            LeverString_SysTreeMainList p = new LeverString_SysTreeMainList();
            string _str = "";
            string strSQL = "select f_id,f_name,f_level,f_type from TS_S_B_Station_WorkPlace where f_del=0 and f_stack>f_stacknum and f_type in (3," + _LoadType + ")";
            SqlConnection conn = new SqlConnection(TS_Win_Class.GetSQlConnStr());
            conn.Open();
            SqlCommand comm = new SqlCommand(strSQL, conn);
            SqlDataReader read = comm.ExecuteReader();
            while (read.Read())
            {
                p = new LeverString_SysTreeMainList();

                if (read["f_level"].ToString() == ",")
                {
                }
                else
                {
                    _str = read["f_level"].ToString();
                    _str = _str.Substring(0, (_str).Length-1);
                    _str = _str.Substring(_str.LastIndexOf(',') + 1);
                    p.f_parent = _str;
                }
                p.f_name = read["f_name"].ToString();
                p.f_id = read["f_id"].ToString();
                p.f_type = read["f_type"].ToString();
                pList.Add(p);
            }
            read.Close();
            conn.Close();
            conn.Dispose();
            tl_Level.DataSource = pList;
        }

        private void bt_Sure_Click(object sender, EventArgs e)
        {
            try
            {
                if (_LoadType == "0")
                {
                    if (_LoadFormType == "0")
                    {
                        Locomotive_Repair_Work_TrainIn_MainForm._MapName = tl_Level.FocusedNode.GetValue("f_name").ToString();
                        Locomotive_Repair_Work_TrainIn_MainForm._MapID = tl_Level.FocusedNode.GetValue("f_id").ToString();
                    }
                    if (_LoadFormType == "1")
                    {
                        Locomotive_Repair_Work_Start_MainForm._MapName = tl_Level.FocusedNode.GetValue("f_name").ToString();
                        Locomotive_Repair_Work_Start_MainForm._MapID = tl_Level.FocusedNode.GetValue("f_id").ToString();
                    }
                }
                if (tl_Level.FocusedNode.GetValue("f_type").ToString() == _LoadType)
                {
                    try
                    {
                        TextBox _tb = (TextBox)this.Tag;
                        _tb.Text = tl_Level.FocusedNode.GetValue("f_name").ToString();
                        _tb.Tag = tl_Level.FocusedNode.GetValue("f_id").ToString();
                    }catch
                    {

                    }
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("你选择的不是有效工位！");
                }
            }
            catch
            {
            }
        }

        private void bt_Exit_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
    }
}